package com.mi.rof.engineer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mi.rof.entity.InventoryTable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * @author : Yang Yu you
 */
public interface InventoryMapper extends BaseMapper<InventoryTable> {
    /**
     * 申请物料
     * @param id 物料id
     * @param value 申请数量
     * @return 是否申请成功
     */
    @Update("UPDATE inventory_table SET quantity = quantity - #{value} WHERE item_id = #{id} AND quantity >= #{value}")
    int applyInventory(@Param("id") String id, @Param("value") Integer value);

    /**
     * 更新物料申请表状态
     * @param orderId 订单id
     * @return 更新的行数
     */
    @Update("UPDATE inventory_apply SET inventory_state = 1 WHERE repair_order_id = #{orderId}")
    Integer updateInventoryState(String orderId);

}
